package com.supermap.dubbo.client.controller;

import com.supermap.dubbo.client.dubbo.UserDubboConsumerService;
import com.supermap.dubbo.service.domain.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping(value = "" )
public class UserController {
    @Resource
    private UserDubboConsumerService userDubboConsumerService;

    @RequestMapping(value = "addUser", method = RequestMethod.POST)
    @ResponseBody
    public int addUser(@RequestBody Map<String,String> param){
        String name = param.get("name");
        String age = param.get("age");
        return userDubboConsumerService.addUser(name, age);
    }

    @RequestMapping(value = "findById")
    @ResponseBody
    public User findById(@RequestBody Map<String,String> param){
        String id = param.get("id");
        return userDubboConsumerService.findById(id);
    }

    @RequestMapping(value = "updataById")
    @ResponseBody
    public void updataById(@RequestBody Map<String,String> param){
        String name = param.get("name");
        String id = param.get("id");
        userDubboConsumerService.updataById(id, name);
    }

    @RequestMapping(value = "deleteById")
    @ResponseBody
    public void deleteById(@RequestBody Map<String,String> param){
        String id = param.get("id");
        userDubboConsumerService.deleteById(id);
    }
}
